<template>
  <div class="newProducts">
    <h1>-精品库新品-</h1>
    <ul class="newProducts-list">
      <li
        v-for="(item, index) in newProductsList"
        :key="index"
        @click="goToDetail(item.productid)"
      >
        <div class="img-box">
          <img :src="item.imgurl" alt="item.title" />
        </div>
        <p>{{ item.title }}</p>
      </li>
    </ul>
  </div>
</template>

<script>
import { getNewProductsApi } from "@/utils/api";
export default {
  data() {
    return {
      // 精品库新品数据
      newProductsList: [],
    };
  },

  // 挂载期获取数据
  mounted() {
    this.getNewProductsData();
  },

  methods: {
    // get方式获取精品库新品数据
    async getNewProductsData() {
      const res = await getNewProductsApi();
      if (res.status === 0) {
        this.newProductsList = res.result;
        // 渲染完成后内容才有了宽高
        await this.$nextTick();
        // 传递给父组件,添加 better-scroll 效果
        this.$emit("finish-getdata");
      }
    },

    // 跳转到对应的详情页
    goToDetail(id) {
      this.$router.push("/newproduct/detail/" + id);
    },
  },
};
</script>

<style lang="less" scoped>
.newProducts {
  width: 100%;

  h1 {
    text-align: center;
    font-size: 32px;
    font-weight: 600;
  }

  .newProducts-list {
    width: 100%;
    height: 710px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 45px 30px 0px 30px;

    li {
      width: 207px;
      text-align: center;

      .img-box {
        width: 207px;
        height: 207px;
        border: 1px solid #bfbfbf;

        img {
          width: 207px;
          height: 207px;
        }
      }

      p {
        font-size: 24px;
        color: #565656;
        width: 100%;
        margin-top: 16px;
        line-height: 30px;
        height: 60px;
        max-height: 60px;
        // 设置多行文本显示省略号
        display: -webkit-box;
        // 设置排列方向
        -webkit-box-orient: vertical;
        // 设置要显示的行数
        -webkit-line-clamp: 2;
        // 溢出的内容隐藏
        overflow: hidden;
      }
    }
  }
}
</style>
